package com.fsc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.fsc.entity.domain.StuHomeworkInfo;

import com.fsc.entity.vo.StudentCompletionVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface StuHomeworkInfoMapper extends BaseMapper<StuHomeworkInfo> {

	List<StudentCompletionVO> selectByHomeworkID(Integer homeworkId, Integer teacherId);

	StudentCompletionVO selectByStudentID(Integer studentId, Integer homeworkId);

	StuHomeworkInfo selectByStudentIdAndHomeworkId(@Param("studentId") Integer studentId, @Param("homeworkId") Integer homeworkId);

	@Insert("INSERT INTO stu_homework_info (student_id, homework_id) VALUES (#{studentId}, #{homeworkId})")
	void save(@Param("studentId") Integer studentId, @Param("homeworkId") Integer homeworkId);

	@Select("SELECT homework_id FROM stu_homework_info WHERE student_id = #{loginId}")
	List<Integer> getHomeworkIdByStudentID(Integer loginId);


	@Update("UPDATE stu_homework_info SET homework_url = #{imageUrl}, homework_details = #{text}, finish = 1, finishtime = #{now} WHERE homework_id = #{homeworkId} AND student_id = #{studentId}")
	void updateHomework(@Param("imageUrl") String imageUrl, @Param("text") String text, @Param("homeworkId") Integer homeworkId, @Param("studentId") Integer studentId, @Param("now") LocalDateTime now);

	void deleteByHomeworkId(Integer homeworkId);
}